#include <iostream>
#include <vector>
#include <windows.h>

using namespace std;

// 动态数组的扩容与内存拷贝性能测试
void ArrayListExtend(int arrNum) {
    std::vector<int> arrList{};
    int extendCount = 0;
    int tmpCapacity = arrList.capacity();
    for (int i = 1; i <= arrNum + 1; i++) {
        arrList.push_back(i);
        if (tmpCapacity != arrList.capacity()) {
            extendCount++;
            cout << "成员个数：" << arrList.size() << ", 数组出现了扩容：" << tmpCapacity << "————>" << arrList.capacity() << endl;
            tmpCapacity = arrList.capacity();
        }
    }
    cout << "累计添加了 " << arrNum << " 个数组元素，扩容次数: " << extendCount << " ,最后一个元素：" << arrList[arrNum - 1] << endl;
}


int main() {
    DWORD startSec = GetTickCount();

    int num = 1000000;  // 依次初始化到100万个数组成员
    for (int i = 0; i < 10; i++) {
        ArrayListExtend(num);
    }

    cout << " 单次平均耗时(ms)：" << (GetTickCount() - startSec) / 10 << endl;
    return 0;
}
